Ext.define('SKJF.view.MASTER.v_mstbarang_form', {
	extend	: 'Ext.form.Panel',
	
	alias	: 'widget.v_mstbarang_form',
	
	region:'east',
	id: 'east-region-container',
	
	title		: 'Create/Update mstbarang',
    bodyPadding	: 5,
    autoScroll	: true,
    
    initComponent: function(){
    	/*
		 * Deklarasi variable setiap field
		 */
		
		var mstsatuan_store = Ext.create('SKJF.store.s_mstsatuan',{autoLoad:true});
		var mstjnsbrg_store = Ext.create('SKJF.store.s_mstjnsbarang',{autoLoad:true});
		var msthscode_store = Ext.create('SKJF.store.s_msthscode',{autoLoad:true});
		
		var KODE_BARANG_field = Ext.create('Ext.form.field.Text', {
			itemId: 'KODE_BARANG_field',
			name: 'KODE_BARANG', /* column name of table */
			fieldLabel: 'KODE_BARANG',
			readOnly:true,
			allowBlank: true
		});
		var NAMA_BARANG_field = Ext.create('Ext.form.field.Text', {
			itemId: 'NAMA_BARANG_field',
			name: 'NAMA_BARANG', /* column name of table */
			fieldLabel: 'NAMA_BARANG',
			maxLength: 50,
			style : {textTransform: "uppercase"},
			enableKeyEvents: true,
			listeners: {
				'change': function(field, newValue, oldValue){
					//field.setValue(newValue.toUpperCase());
					Ext.util.Format.capitalize = (function(){
						var re = /(^|[^\w])([a-z])/g,
							fn = function(m, a, b) {
								return a + b.toUpperCase();
							};
						return function(v){
							return v.toLowerCase().replace(re, fn);
						}
					})();
					field.setValue(Ext.util.Format.capitalize(newValue));
				}
			}
		});
		var JENIS_BARANG_field = Ext.create('Ext.form.field.ComboBox', {
			name: 'JENIS_BARANG', /* column name of table */
			fieldLabel: 'JENIS_BARANG',
			pageSize: 10,
			typeAhead    : true,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: mstjnsbrg_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{KODE_JENIS_BARANG} - {JENIS_BARANG}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{JENIS_BARANG}',
				'</tpl>'
			),
			valueField: 'JENIS_BARANG',
			displayField: 'JENIS_BARANG'
		});
		var SATUAN_field = Ext.create('Ext.form.field.ComboBox', {
			name: 'SATUAN', /* column name of table */
			fieldLabel: 'SATUAN',
			pageSize: 10,
			typeAhead    : true,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: mstsatuan_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{NAMA_SATUAN}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{NAMA_SATUAN}',
				'</tpl>'
			),
			valueField: 'NAMA_SATUAN',
			displayField: 'NAMA_SATUAN'
		});
		var HSCODE_field = Ext.create('Ext.form.field.ComboBox', {
			name: 'HSCODE', /* column name of table */
			fieldLabel: 'HSCODE',
			pageSize: 10,
			typeAhead    : true,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: msthscode_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{HSCODE}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{HSCODE}',
				'</tpl>'
			),
			valueField: 'HSCODE',
			displayField: 'HSCODE'
		});
		var STOCK_field = Ext.create('Ext.form.field.Number', {
			name: 'STOCK', /* column name of table */
			fieldLabel: 'STOCK'
		});		
        Ext.apply(this, {
            fieldDefaults: {
                labelAlign: 'right',
                labelWidth: 120,
                msgTarget: 'qtip',
				anchor: '100%'
            },
			defaultType: 'textfield',
            items: [KODE_BARANG_field,NAMA_BARANG_field,JENIS_BARANG_field,SATUAN_field,HSCODE_field,STOCK_field],
			
	        buttons: [{
                iconCls: 'icon-save',
                itemId: 'save',
                text: 'Save',
                disabled: true,
                action: 'save'
            }, {
                iconCls: 'icon-add',
				itemId: 'create',
                text: 'Create',
                action: 'create'
            }, {
                iconCls: 'icon-reset',
                text: 'Cancel',
                action: 'cancel'
            }]
        });
        
        this.callParent();
    }
});